www.gusucode.com > VC++ 更改文件属性为只读系统或隐藏源码程序 > VC++ 更改文件属性为只读系统或隐藏源码程序\code\FileOP.cpp
// FileOP.cpp: implementation of the CFileOP class. // download by http://www.NewXing.com ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "FileExample.h" #include "FileOP.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CFileOP::CFileOP() { } CFileOP::~CFileOP() { } BOOL CFileOP::Copy(CString strSourcePath, CString strTargetPath) { CFile fSource, fTarget; //定义4k字节的缓冲区 char c[4096]; int nCount; //打开文件 if (!fSource.Open(strSourcePath, CFile::modeRead)) { AfxMessageBox("Open Source File Fail!"); return false; } if (!fTarget.Open(strTargetPath, CFile::modeCreate | CFile::modeWrite)) { AfxMessageBox("Create Target File Fail!"); return false; } //读文件到缓冲区c nCount = fSource.Read(c, 4096); while (nCount) { fTarget.Write(c, nCount); nCount = fSource.Read(c, 4096); } fSource.Close(); fTarget.Close(); return true; }